#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: extractapk.sh
# Description: 
#   
# Edit History: 
#   2011-01-19    File created.
#========================================================================
APKTOOL="$HOME/apktool/apktool"
DEX2JAR="$HOME/dex2jar-0.0.7.5-SNAPSHOT"
BAKSMALI="$HOME/apktool/baksmali-1.2.7.jar"

_classpath="."
for k in $DEX2JAR/lib/*.jar
do
	_classpath="${_classpath}:${k}"
done

#解開所有apk,與classes.dex
find . -name "*.apk" -maxdepth 1 -exec $APKTOOL d {} \; -exec unzip {} classes.dex \; -exec mv classes.dex {}.dex \; -exec java  -classpath "${_classpath}" "pxb.android.dex2jar.v3.Main" {}.dex \;

#取出所有apk的AndroidManifest.xml觀察
find . -name AndroidManifest.xml -maxdepth 2 -exec echo {} \; -exec cat {} \;  > observed.xml

#取得smali dump file
find . -name "*.apk" -maxdepth 1 -exec java -jar $BAKSMALI {} -N -D {}.dumpdex \;

#列出所有apktool d 失敗的目錄
echo "" >failapk;
for dir in ./*/
do
	if [ ! -e $dir/AndroidManifest.xml ] ; then
		echo $dir >> failapk ;
	fi
done

